/**
 * User: alesj
 * Date: 2004.8.11
 * Time: 16:34:57
 */

package com.generalynx.ecos.data.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.alesj.newsfeed.data.Contact;
import com.alesj.newsfeed.data.Group;
import com.alesj.newsfeed.data.GroupEntry;
import com.alesj.newsfeed.data.Message;
import com.alesj.newsfeed.data.MessageCriteria;
import com.generalynx.common.data.IEntity;
import com.generalynx.common.data.dao.IEntityDAO;
import com.generalynx.common.web.module.Module;
import com.generalynx.ecos.data.Role;
import com.generalynx.ecos.data.User;
import com.generalynx.ecos.data.UserRole;
import com.generalynx.ecos.data.types.Status;
import com.generalynx.ecos.page.Page;
import com.generalynx.ecos.page.PageScroll;
import org.hibernate.LockMode;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.type.Type;
import org.springframework.dao.DataAccessException;

public interface IBasicDAO extends IEntityDAO {

    static final String basicDAO = "basicDAO";

    /* IEntity advanced */

    IEntity loadEntity(Class clazz, int id, LockMode lockMode) throws DataAccessException;
    void deleteEntity(IEntity entity, LockMode lockMode) throws DataAccessException;
    List findEntity(String query, Object value, Type type) throws DataAccessException;
    List findEntity(String query, Object[] values, Type[] types) throws DataAccessException;
    List findEntity(PageScroll pageScroll) throws DataAccessException;
    void evict(IEntity entity) throws DataAccessException;
    void initialize(Object object) throws DataAccessException;

    /* Session */

    void flush() throws DataAccessException;

    /* Common */

    Module loadRootModule(Map nameModuleMap,Map idModuleMap) throws DataAccessException;
    Module loadModule(int id) throws DataAccessException;

    /* Default */

    /* User */

    User loadUser(int id) throws DataAccessException;
    List findUser(String username) throws DataAccessException ;
    List findUser(String username, String role) throws DataAccessException ;
    List findUser(String username, String password, String role) throws DataAccessException ;
    List findUsers() throws DataAccessException ;
    List findUsers(String role) throws DataAccessException ;

    /* Role */

    Role loadRole(int id) throws DataAccessException;
    Role loadRole(String roleName) throws DataAccessException;
    List findRoles() throws DataAccessException;

    /* UserRole */

    UserRole loadUserRole(int userId, int roleId) throws DataAccessException;
    void saveUserRole(UserRole userRole) throws DataAccessException;
    void deleteUserRole(UserRole userRole) throws DataAccessException;

    /* Pagination */

    Page loadPage(String hql, int pageNumber, int pageSize) throws DataAccessException;
    Page loadPage(DetachedCriteria criteria, int pageNumber, int pageSize) throws DataAccessException;

    /* Advanced DAO */

    Contact getContact(int contactId) throws DataAccessException;
    Contact loadContact(int contactId) throws DataAccessException;
    List findContacts(String query, Set<MessageCriteria>criteria) throws DataAccessException;
    List findContacts(String query, Set<MessageCriteria>criteria, Status[] acceptedStatus) throws DataAccessException;
    List findContacts(int[] entries, int[] excludes, boolean isConjunction) throws DataAccessException;
    List findContacts(int[] entries, int[] excludes, boolean isConjunction, Status[] acceptedStatus) throws DataAccessException;

    Group loadGroup(int id) throws DataAccessException;

    GroupEntry loadGroupEntry(int id) throws DataAccessException;

    Message loadMessage(int messageId) throws DataAccessException;
    List findMessages(String subject, Date from, Date till, User creator, int failed) throws DataAccessException;

}
